/**
 * 
 */
package com.ginger.rabbitmq.exchange.api.consumer;

import com.ginger.properties.RabbitMQProperties;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Description: 生产者
 * @author 姜锋
 * @date 2019年3月29日 上午9:40:05
 * @version V1.0
 */
public class Producer {
	public static void main(String[] args) throws Exception {
		// 1.创建连接工厂
		ConnectionFactory connectionFactory = new ConnectionFactory();
		// 1.1设置连接信息
		connectionFactory.setHost(RabbitMQProperties.RABBITMQ_HOST);
		connectionFactory.setPort(RabbitMQProperties.RABBITMQ_PORT);
		connectionFactory.setVirtualHost(RabbitMQProperties.RABBITMQ_VIRTUAL_HOST);
		connectionFactory.setUsername(RabbitMQProperties.USER_NAME);
		connectionFactory.setPassword(RabbitMQProperties.PASSWORD);
		// 2.通过连接工厂创建连接
		Connection connection = connectionFactory.newConnection();
		// 3.通过connection创建
		Channel channel = connection.createChannel();
		// 4.声明
		String exchangeName = "test_consumer_exchange";
		String routingKey = "consumer.save";
		String message;
		for (int i = 0; i < 2048*1024; i++) {
			
			AMQP.BasicProperties properties = 
					new AMQP.BasicProperties.Builder()
					.deliveryMode(2)
					.contentEncoding("UTF-8")
					.expiration("10000")
					.build();
			message = "这是 "+(i+1)+"条生产的数据:  Hello RabbitMQ Send consumer message !";
			channel.basicPublish(exchangeName, routingKey, true, properties, message.getBytes());

		}
		channel.close();
		connection.close();
	}
}
